import {
	createRouter,
	createWebHashHistory
} from "vue-router"
import { routes } from "./routes.js"
import { useWarningNotice } from '@u/notice.js';

const router = createRouter({
	history: createWebHashHistory(),
	routes
})

router.beforeEach(to => {
	const token = localStorage.getItem("token")
	const isInManageRouteGroup = /^Manage(?!(Login))/.test(to.name)
	const isToLogin = !token && isInManageRouteGroup
	if (isToLogin) {
		useWarningNotice({
			message: "无此权限，请先登录"
		})
		return { name: "ManageLogin" }
	}
	return true
})

export default router
